<!-- 公司详情 -->
<template>
    <page-header-wrapper @back="() => $router.go(-1)">
        <a-card :bordered="false" title="基本信息">
            <a-descriptions >
                <a-descriptions-item label="公司名称" >{{company.companyName}}</a-descriptions-item>
                <a-descriptions-item label="统一社会信用代码" >{{company.socialCode}}</a-descriptions-item>
                <a-descriptions-item label="状态" >{{company.state | contractStatusFilter}}</a-descriptions-item>
                <a-descriptions-item label="联系人" >{{company.contactName}}</a-descriptions-item>
                <a-descriptions-item label="联系电话" >{{company.contactPhone}}</a-descriptions-item>
                <a-descriptions-item label="营业执照" ><a href="javascript:void(0)" @click="lookLicense(company.businessLicense)">查看</a></a-descriptions-item>
                <a-descriptions-item label="备注" :span="3">{{company.remark ?? '-'}}</a-descriptions-item>
            </a-descriptions>
        </a-card>
        <a-card style="margin-top:20px" :bordered="false" title="实名认证">
            <a-button slot="extra" v-if="company.realNameStatus == 0 || company.realNameStatus == 1 || company.realNameStatus == 2" type='primary' @click="goAuth">{{ company.realNameStatus == 0 || company.realNameStatus == 1 || company.realNameStatus == 2 ? '去认证' : '重新认证'}}</a-button>
            <a-descriptions >
                <a-descriptions-item label="认证状态" >{{company.realNameStatus | realNameStatusFilter}}</a-descriptions-item>
                <a-descriptions-item label="认证时间" >{{company.authTime ?? '-'}}</a-descriptions-item>
                <a-descriptions-item label="组织机构名称" >{{company.companyName}}</a-descriptions-item>
                <a-descriptions-item label="法人姓名" >-</a-descriptions-item>
                <a-descriptions-item label="组织机构证件类型" >统一社会信用代码</a-descriptions-item>
                <a-descriptions-item label="组织机构证件号" >{{company.socialCode}}</a-descriptions-item>
                <a-descriptions-item label="法人证件类型" >-</a-descriptions-item>
                <a-descriptions-item label="法人证件号" >-</a-descriptions-item>
            </a-descriptions>
        </a-card>
        <a-card style="margin-top:20px" :bordered="false" title="自动签授权">
            <a-button v-if="company.authorizeStatus == 0" slot="extra" type='primary' :disabled="company.realNameStatus != 3" @click="goAuthorize">去授权</a-button>
            <a-descriptions >
                <a-descriptions-item label="授权状态" >{{company.authorizeStatus == 0 ? '未授权' : '已授权'}}</a-descriptions-item>
                <a-descriptions-item label="授权生效时间" >{{company.esignEffectiveTime ?? '-'}}</a-descriptions-item>
                <a-descriptions-item label="授权失效时间" >{{company.esignExpireTime ?? '-'}}</a-descriptions-item>
            </a-descriptions>
        </a-card>

        <!-- 预览图片 -->
        <a-modal :visible="previewVisible" :footer="null" @cancel="previewVisible = false">
            <img alt="example" style="width: 100%" :src="previewImage" />
        </a-modal>
    </page-header-wrapper> 
</template>

<script>
import { getCompayDetail , authCompany , authorizeCompany } from '@/api/services/company';
export default {
    data () {
        return {
            companyId: '',
            company: {
                companyName: '',
                socialCode: '',
                state: '1',
                contactName: '',
                contactPhone: '',
                remark: null,
                realNameStatus: 0,
                authTime: null,
                companyName: '',
                socialCode: '',
                authorizeStatus: 0,
                esignEffectiveTime: null,
                esignExpireTime: null,
            },
            previewVisible: false,
            previewImage: '',
        };
    },
    created(){
        this.companyId = this.$route.query.companyId;
        this.getDetail();
    },
    methods: {
        // 获取详情信息
        getDetail(){
            let _this = this;
            getCompayDetail(_this.companyId)
            .then(res => {
                if(res.success){
                    _this.company = JSON.parse(JSON.stringify(res.data));
                }else{
                    _this.$notification['error']({
                        message: '温馨提示',
                        description: res.errMessage,
                        duration: 8
                    })
                }
            })
        },
        // 去认证
        goAuth(){
            let _this = this;
            authCompany(_this.companyId)
            .then(res => {
                if(res.success){
                    window.open(res.data)
                }else{
                    _this.$notification['error']({
                        message: '温馨提示',
                        description: res.errMessage,
                        duration: 8
                    })
                }
            })
        },
        // 去授权
        goAuthorize(){
            let _this = this;
            authorizeCompany(_this.companyId)
            .then(res => {
                if(res.success){
                    window.open(res.data)
                }else{
                    _this.$notification['error']({
                        message: '温馨提示',
                        description: res.errMessage,
                        duration: 8
                    })
                }
            })
        },
        // 查看营业执照
        lookLicense(src){
            this.previewImage = src;
            this.previewVisible = true;
        },
    }
}

</script>
<style scoped>

</style>